<?php
header("content-type:text/html;charset=utf-8");
$redis=new Redis();
$redis->connect('127.0.0.1','6379');
$id=$_POST['id'];
$sdn=("mysql:host=127.0.0.1;dbname=myexam;charset=utf8");
$pdo=new PDO($sdn,'root','root');
$sql="select shu from pro where id=$id";
$res=$pdo->query($sql)->fetch();
//print_r($res);die;
if($redis->lPop("data".$id))
{

    $sql="update pro set shu = shu-1 where id=$id";
    $info=$pdo->exec($sql);
    if($info)
    {
        $data=array('code'=>1,"msa"=>"抢购成功");
    }

}
else
{
    $data=array('code'=>0,"msa"=>"对不起，抢光了");
}

echo json_encode($data);
























